import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
    {
        path: "/",
        name: "Layout",
        meta: {title: "首页"},
        redirect: {name: "Login"},
        component: () => import("@/views/layout"),
    },
    {
        path: "/login",
        name: "Login",
        meta: {title: "登录"},
        component: () =>
            import(/* webpackChunkName: "about" */ "@/views/login"),
    },
    {
        path: "*",
        name: "notfound",
        meta: {title: "404"},
        component: () =>
            import(/* webpackChunkName: "about" */ "@/views/notfound.vue"),
    },
];

const router = new VueRouter({
    mode: "history",
    base: process.env.BASE_URL,
    routes,
});


// 添加守卫
router.beforeEach((to, from, next) => {
    // console.info("前置守卫工作")
    // console.log(to.matched)
    next()
})

router.afterEach((to, from) => {
    // console.info("后置守卫工作")
    document.title = to.meta.title
})

export default router;
